package com.bw.as_bd_plugin;

import android.annotation.SuppressLint;
import android.util.Log;

import androidx.annotation.Nullable;

import io.flutter.plugin.common.MethodChannel;

/**
 * @ClassName: ResultStateful$
 * @Description: java类作用描述
 * @Author: 魏靳元
 * @CreateDate: 2022/8/2 08:29
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class ResultStateful implements MethodChannel.Result {
    private final static String TAG = "ResultStateful";
    private MethodChannel.Result mYresult;
    private boolean called;

    public static ResultStateful of(MethodChannel.Result result) {
        return new ResultStateful(result);
    }

    private ResultStateful(MethodChannel.Result result) {
        this.mYresult = result;
    }

    @Override
    public void success(@Nullable Object o) {
        Log.i(TAG, "success: ");
        if (called) {
            printError();
            return;
        }
        called = true;
        mYresult.success(o);
    }

    @Override
    public void error(String s, @Nullable String s1, @Nullable Object o) {
        if (called) {
            printError();
            return;
        }
        called = true;
        mYresult.error(s, s1, o);
    }

    @Override
    public void notImplemented() {
        if (called) {
            printError();
            return;
        }
        called = true;
        mYresult.notImplemented();

    }

    private void printError() {
        Log.e(TAG, "error:result called");
    }
} 
